using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Assets.Helpers;
using Microsoft.VisualStudio.Shell;
using VSSDKAssist.Assets.Actions.Base;
using System.Globalization;

namespace VSSDKAssist.Recipes.CreateVSToolWindow
{
	/// <summary>
	/// Action that adds/update the ProvideToolWindow attribute
	/// </summary>
	public class AddProvideToolWindowAttributeAction : ActionBase
	{
		#region Properties
		private CodeClass codeClass;

		/// <summary>
		/// Gets or sets the code class.
		/// </summary>
		/// <value>The code class.</value>
		[Input(Required = true)]
		public CodeClass CodeClass
		{
			get { return codeClass; }
			set { codeClass = value; }
		}

		private string toolWindowName;

		/// <summary>
		/// Gets or sets the name of the tool window.
		/// </summary>
		/// <value>The name of the tool window.</value>
		[Input(Required = true)]
		public string ToolWindowName
		{
			get { return toolWindowName; }
			set { toolWindowName = value; }
		}

		private string toolWindowNamespace;

		/// <summary>
		/// Gets or sets the tool window namespace.
		/// </summary>
		/// <value>The tool window namespace.</value>
		[Input(Required = true)]
		public string ToolWindowNamespace
		{
			get { return toolWindowNamespace; }
			set { toolWindowNamespace = value; }
		}

		private Guid windowGuid;
		/// <summary>
		/// Gets or sets the window GUID.
		/// </summary>
		/// <value>The window GUID.</value>
		[Input(Required = true)]
		public Guid WindowGuid
		{
			get { return windowGuid; }
			set { windowGuid = value; }
		}

		private VsDockStyle dockStyle;

		/// <summary>
		/// Gets or sets the dock style.
		/// </summary>
		/// <value>The dock style.</value>
		[Input(Required = true)]
		public VsDockStyle DockStyle
		{
			get { return dockStyle; }
			set { dockStyle = value; }
		}

		private ToolWindowOrientation orientation;

		/// <summary>
		/// Gets or sets the orientation.
		/// </summary>
		/// <value>The orientation.</value>
		[Input(Required = true)]
		public ToolWindowOrientation Orientation
		{
			get { return orientation; }
			set { orientation = value; }
		}

		private bool multiInstances;

		/// <summary>
		/// Gets or sets a value indicating whether [multi instances].
		/// </summary>
		/// <value><c>true</c> if [multi instances]; otherwise, <c>false</c>.</value>
		[Input(Required = true)]
		public bool MultiInstances
		{
			get { return multiInstances; }
			set { multiInstances = value; }
		}

		private bool transient;

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="AddProvideToolWindowAttributeAction"/> is transient.
		/// </summary>
		/// <value><c>true</c> if transient; otherwise, <c>false</c>.</value>
		[Input(Required = true)]
		public bool Transient
		{
			get { return transient; }
			set { transient = value; }
		}
		#endregion

		#region Protected Implementation
		/// <summary>
		/// Called when [execute].
		/// </summary>
		protected override void OnExecute()
		{
			string attName = "ProvideToolWindow";
			string attValue =
				string.Format(
					CultureInfo.CurrentCulture,
					"typeof({0}.{1}), MultiInstances = {2}, Style = VsDockStyle.{3}, Orientation = ToolWindowOrientation.{4}, Transient = {5}, Window = \"{6}\"",
					this.toolWindowNamespace,
					this.toolWindowName,
					this.multiInstances.ToString().ToLower(CultureInfo.CurrentCulture),
					this.dockStyle,
					this.orientation,
					this.transient.ToString().ToLower(CultureInfo.CurrentCulture),
					this.windowGuid.ToString("B"));

			FileCodeModelHelper.AddAttribute(codeClass, attName, attValue, false);
		}
		#endregion
	}
}